/*
 * BtreeNode.h
 *
 *  Created on: Oct 26, 2011
 *      Author: hxu
 */

#ifndef BTREENODE_H_
#define BTREENODE_H_
#include <ostream>
#include "Wire.h"

namespace Cxuh {

class BtreeNode {
	friend class Btree3D;
public:
	BtreeNode();
	BtreeNode(int id1, char nodetype);
	BtreeNode(int id1, char nodetype, int x1, int y1, int z1);
	BtreeNode(int id1, char nodetype, int x1, int y1, int z1, int z12);
	virtual ~BtreeNode();
	void setXYZ(int x1, int y1, int z1) {
		x = x1;
		y = y1;
		z = z1;
	}
	virtual int getZ2();
	virtual void setXYZ(int, int, int, int);

	int getX() const {
		return x;
	}
	int getY() const {
		return y;
	}
	int getZ() const {
		return z;
	}

	virtual double getCin() const {
		return csink;
	}
	virtual double getRout() const {
		return 0;
	}
	int getID() const {
		return id;
	}

	virtual double getD() const {
		return 0.0;
	}

	void setCsink(double c) {
		csink = c;
	}

	void calc_elmore_delay_tosink(); // calculate the min and max path delay
	double get_in_cload() const; // get the c load seen at the input of this node
	char getType() const {
		return type;
	}
	
	Wire* get_pre_wire() const{
		return pre_wire;
	}

	void setLchild(BtreeNode * lchd);
	void setRchild(BtreeNode * rchd);
	BtreeNode* getLchild() const {
		return lchild;
	}
	BtreeNode* getRchild() const {
		return rchild;
	}
	BtreeNode* getParent() const {
		return parent;
	}
	void setChild(BtreeNode * chd);
	void setID(int i);
	std::string getName() const;
	void set_pre_wire(Wire& wire1) {
		pre_wire = &wire1;
	}
	double getDmin() const {
		return dmin;
	}
	double getDmax() const {
		return dmax;
	}

	friend int operator-(const BtreeNode&, const BtreeNode&);
	friend std::ostream& operator<<(std::ostream&, BtreeNode& obj);

protected:
	int id;
	char type;
	BtreeNode* parent;
	BtreeNode* lchild, *rchild; // left and right children
	int x, y, z;
	std::string name;
	double dmin, dmax; // the min/max delay to its sinks
	Wire* pre_wire;
	double csink; // input cap of the sink

	void initBtreeNode(); // initialization
};

}

#endif /* BTREENODE_H_ */
